package sql;
import java.sql.*;
import java.util.*;


public class DataAccess 
{
	Connection conn = null;
	String username = "sshresth";
	String password = "316442";
	
	private static void checkDriver() throws ClassNotFoundException 
	{			
		Class.forName("oracle.jdbc.driver.OracleDriver");		
	}
	
	public void getConnection() throws SQLException 
	{
		//create connection if there is no connection
		if(conn == null)
		{
			conn = DriverManager.getConnection
					   ("jdbc:oracle:thin:"+username+"/"+password+"@CSCORACLE.carrollu.edu:1522:csorcl");			
		}
	}
	
	//Returns result set for the select query
	public ResultSet getSelectResult(String query) throws ClassNotFoundException, SQLException 
	{
		checkDriver();
		getConnection();
		Statement stmt;
		
		stmt = conn.createStatement();
		return stmt.executeQuery(query);				
	}
	
	//executes insert query 
	public void modifyTable(String query) throws ClassNotFoundException, SQLException
	{
		checkDriver();
		getConnection();
		Statement stmt;
		
		stmt = conn.createStatement();
		stmt.executeUpdate(query);
	}
}
